package com.chezhujie.www.controller;



import com.chezhujie.www.service.CzjadvertisementimgService;
import com.chezhujie.www.utils.DESUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;





@Controller
@RequestMapping("zqcb")
public class CzjzhiqunchebaoController extends BaseController {
	private static final Logger log = LoggerFactory.getLogger(CzjzhiqunchebaoController.class);
	public CzjzhiqunchebaoController() {
	}
 
 
 	/**
	 * czj_advertisementImg  图片广告新增页面
	 * 
	 * @param request
	 * @param model
	 * @return
 	 * @throws Exception 
	 */
	@RequestMapping("right.do")
	public String add(HttpServletRequest request, 
			HttpServletResponse response,
			@RequestParam(required=true) String phone,
			@RequestParam(required=true) String url,
			ModelMap model) throws Exception {
			
			String appId = "W39cIeTEN1R3";
			String cryptStr2 =null;
	        try {	
		        String appKey = "kiTekj114kgSi12TkTTkQtQ8924951Rs";
		        String input = "{\"unique_id\":\""+phone+"\",\"type\":\"mobile\"}";
		        DESUtils crypt2 = new DESUtils(appKey);
		        cryptStr2 = crypt2.encrypt(input);									
			} catch (Exception e) {
	         log.error("授权错误",e);
	         jsonResult(0, "203", "授权错误,系统异常", "",response);
	         return null;
			}
		System.out.println(url+"?appId="+appId+"&securityStr="+cryptStr2);
		return "redirect:"+url+"?appId="+appId+"&securityStr="+cryptStr2;
	}


   
	/**
	 * 设置页面所需的数据字典
	 * @param model
	 */
	private void setDict(ModelMap model){
		
	}
 
	//删除更新的图片
	 public void deleteFile(String jgpName){	 
		 File f = new File(jgpName); // 输入要删除的文件位置
		 if(f.exists()){
			 f.delete();
		 }
		
	 }	
     
	@Resource
	private CzjadvertisementimgService czjadvertisementimgService;


}